package com.cdks.wuxiu.api.service.mysql;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdks.wuxiu.api.mapper.UserExtendInfoMapper;
import com.cdks.wuxiu.entity.mysql.UserExtendInfo;

import org.springframework.stereotype.Service;

/**
 * 用户扩展信息 服务实现类
 */
@Service
public class UserExtendInfoServiceImpl extends ServiceImpl<UserExtendInfoMapper, UserExtendInfo> implements UserExtendInfoService {
    @Override
    public int saveInfo(UserExtendInfo userInfo) {
        UpdateWrapper<UserExtendInfo> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(UserExtendInfo::getUserId, userInfo.getUserId());

        int ret  = baseMapper.update(userInfo, updateWrapper);
        if (ret == 0)
        {
            baseMapper.insert(userInfo);
        }

        return 0;
    }

    @Override
    public UserExtendInfo getInfoByUserId(long userId) {
        QueryWrapper<UserExtendInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(UserExtendInfo::getUserId, userId)
                    .select(UserExtendInfo::getAstro,
                            UserExtendInfo::getBirthday,
                            UserExtendInfo::getCity,
                            UserExtendInfo::getHeight,
                            UserExtendInfo::getHobby,
                            UserExtendInfo::getLoveState,
                            UserExtendInfo::getSlogan,
                            UserExtendInfo::getUserId,
                            UserExtendInfo::getVoice,
                            UserExtendInfo::getWeight,
                            UserExtendInfo::getWork,
                            UserExtendInfo::getZodiac);

        return baseMapper.selectOne(queryWrapper);
    }
}
